package com.itheima.service.impl.sms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.core.PageInfo;
import com.itheima.mapper.sms.SmsHomeAdvertiseMapper;
import com.itheima.pojo.sms.SmsHomeAdvertise;
import com.itheima.service.sms.SmsHomeAdvertiseService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsHomeAdvertiseServiceImpl extends ServiceImpl<SmsHomeAdvertiseMapper, SmsHomeAdvertise> implements SmsHomeAdvertiseService {

   /* @Autowired
    private SmsHomeAdvertiseMapper homeAdvertiseMapper;*/

    //修改状态
    @Override
    public void updateStatus(Integer id, Integer status) {
        SmsHomeAdvertise smsHomeAdvertise = this.getById(id);
       smsHomeAdvertise.setStatus(status);
       this.updateById(smsHomeAdvertise);
    }

    //分页查询  TODO 没有加入时间判断
    @Override
    public PageInfo getList(Integer pageNum, Integer pageSize, String name, Integer type, String endTime) {
        Page<SmsHomeAdvertise> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SmsHomeAdvertise> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(type != null, SmsHomeAdvertise::getType, type);
        wrapper.like(name != null, SmsHomeAdvertise::getName, name);
        wrapper.like(endTime != null, SmsHomeAdvertise::getEndTime, endTime);
        Page<SmsHomeAdvertise> advertisePage = this.page(page, wrapper);
        PageInfo pageInfo = new PageInfo();
        pageInfo.setList(advertisePage.getRecords());
        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);
        pageInfo.setTotalPage((int) page.getPages());
        return pageInfo;
    }
}
